﻿<UserControl x:Class="XbdSoft.WPFVersion.View.DownloadView"
     xmlns:toolkit="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:WPFVersion="clr-namespace:XbdSoft.WPFVersion.ViewModel"
             mc:Ignorable="d" Loaded="UserControl_Loaded" Name="Root" FontSize="12" 
             d:DesignHeight="400" d:DesignWidth="600">
    <Grid Margin="0"  Name="layoutRoot">
        <Grid.Resources>
            <WPFVersion:StringArrayConverter x:Key="stringArrayConverter"/>
            <WPFVersion:SelectedDownloadStatusConverter x:Key="selectedDownloadStatusConverter"/>
            <WPFVersion:DownloadStatusImageConverter x:Key="downloadStatusImageConverter"/>
            <WPFVersion:SizeConverter x:Key="sizeConverter"/>
            <WPFVersion:ImageSourceConverter x:Key="imageSourceConverter"/>
            <WPFVersion:AgesConverter x:Key="agesConverter"/>
            <Style TargetType="{x:Type ListBoxItem}">
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Background" Value="#A2D2EB"></Setter>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Grid.Resources>
    	<Grid.Background>
    		<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,-0.2">
    			<GradientStop Color="#FFA0E8FF"/>
    			<GradientStop Color="#FFFEFEFE" Offset="1"/>
    		</LinearGradientBrush>
    	</Grid.Background>
        <Grid.RowDefinitions>
            <RowDefinition Height="25"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="150" MaxWidth="250" MinWidth="100"></ColumnDefinition>
            <ColumnDefinition Width="2"></ColumnDefinition>
            <ColumnDefinition Width="*"></ColumnDefinition>
        </Grid.ColumnDefinitions>

        <StackPanel Width="450" Orientation="Horizontal" HorizontalAlignment="Left" Grid.ColumnSpan="2" Grid.Column="1" VerticalAlignment="Center" Margin="0,2">
            <StackPanel Margin="10,0,0,0" Orientation="Horizontal" HorizontalAlignment="Left">
                <CheckBox Height="16" HorizontalAlignment="Left" Name="SelectAllCheckbox" Content="全选" VerticalAlignment="Top" Margin="0,4,4,0"
                         Command="{Binding SelectAllResourceCommand}" CommandParameter="{Binding ElementName=SelectAllCheckbox,Path=IsChecked}"/>
                <CheckBox Height="16" HorizontalAlignment="Left" Name="SelectOthersCheckbox" Content="反选" VerticalAlignment="Top" Margin="0,4,4,0"
                       Command="{Binding SelectOthersResourceCommand}"/>
            </StackPanel>
            <StackPanel Margin="20,0,0,0" Orientation="Horizontal" HorizontalAlignment="Right">
                <Button Name="PauseSelectedButton" Margin="5,0,0,0"  Cursor="Hand" Content="暂停" ToolTip="暂停"  Width="60"
                        Command="{Binding PauseSelectedCommand}">
                    <Button.Background>
                        <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                            <GradientStop Color="#FFCDCDCD" Offset="0"/>
                            <GradientStop Color="#FFEBEBEB" Offset="0.004"/>
                            <GradientStop Color="#FFEFA54A" Offset="0.543"/>
                            <GradientStop Color="#FFF9D6AA" Offset="1"/>
                            <GradientStop Color="#FFF9D6AA"/>
                        </LinearGradientBrush>
                    </Button.Background>
                </Button>
                <Button Name="DownloadSelectedButton" Margin="5,0,0,0"  Cursor="Hand" Content="下载" ToolTip="下载"  Width="60"
                        Command="{Binding DownloadSelectedCommand}">
                    <Button.Background>
                        <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                            <GradientStop Color="#FFCDCDCD" Offset="0"/>
                            <GradientStop Color="#FFEBEBEB" Offset="0.004"/>
                            <GradientStop Color="#FFEFA54A" Offset="0.543"/>
                            <GradientStop Color="#FFF9D6AA" Offset="1"/>
                            <GradientStop Color="#FFF9D6AA"/>
                        </LinearGradientBrush>
                    </Button.Background>
                </Button>
                <Button Name="DeleteSelectedButton" Margin="5,0,0,0"  Cursor="Hand" Content="删除" ToolTip="删除"  Width="60"
                        Command="{Binding DeleteSelectedCommand}">
                    <Button.Background>
                        <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                            <GradientStop Color="#FFCDCDCD" Offset="0"/>
                            <GradientStop Color="#FFEBEBEB" Offset="0.004"/>
                            <GradientStop Color="#FFEFA54A" Offset="0.543"/>
                            <GradientStop Color="#FFF9D6AA" Offset="1"/>
                            <GradientStop Color="#FFF9D6AA"/>
                        </LinearGradientBrush>
                    </Button.Background>
                </Button>
                <Button Name="OpenDownloadLocationSelectedButton" Margin="5,0,0,0"  Cursor="Hand" Content="存储目录" ToolTip="打开存储目录"  Width="60"
                        Command="{Binding OpenDownloadLocationCommand}">
                    <Button.Background>
                        <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                            <GradientStop Color="#FFCDCDCD" Offset="0"/>
                            <GradientStop Color="#FFEBEBEB" Offset="0.004"/>
                            <GradientStop Color="#FFEFA54A" Offset="0.543"/>
                            <GradientStop Color="#FFF9D6AA" Offset="1"/>
                            <GradientStop Color="#FFF9D6AA"/>
                        </LinearGradientBrush>
                    </Button.Background>
                </Button>
            </StackPanel>
        </StackPanel>
        <Grid Grid.Column="0" Grid.Row="0" Grid.RowSpan="3">
            <Grid.RowDefinitions>
                <RowDefinition Height=".6*"></RowDefinition>
                <RowDefinition Height="1"></RowDefinition>
                <RowDefinition Height=".4*"></RowDefinition>
            </Grid.RowDefinitions>
            <ListBox Name="downloadCategoryListView" Background="Transparent" ItemsSource="{Binding DownloadStatusValueMapping}" DisplayMemberPath="Value"
                      SelectedIndex="{Binding Path=SelectedStatus,Converter={StaticResource selectedDownloadStatusConverter},Mode=TwoWay}"
                      BorderThickness="0" Padding="0" Margin="0" Grid.Row="0">
            </ListBox>
            <GridSplitter Grid.Row="1" Margin="0" Padding="0"  Background="Gray" VerticalAlignment="Stretch"></GridSplitter>
            <StackPanel Grid.Row="2"></StackPanel>
        </Grid>
        <GridSplitter Margin="0" Padding="0" Background="Gray" HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="0" Grid.RowSpan="3"></GridSplitter>
        <Grid  Grid.Column="2" Grid.Row="1"  >
            <Grid.RowDefinitions>
                <RowDefinition Height=".65*"/>
                <RowDefinition Height=".35*"/>
            </Grid.RowDefinitions>
            <GroupBox Header="详细信息："  Padding="2" Grid.Row="1" BorderBrush="LightBlue" Background="Transparent">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="80"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <TextBlock Grid.Column="0" HorizontalAlignment="Right" Grid.Row="0"  Foreground="Gray" Text="作者：">
                    </TextBlock>
                    <TextBlock Grid.Column="1" Grid.Row="0"  Text="{Binding Path=SelectedResource.Resource.Author,Mode=OneWay}">
                    </TextBlock>
                    <TextBlock Grid.Column="0" HorizontalAlignment="Right" TextWrapping="Wrap" Grid.Row="1"  Foreground="Gray" Text="关键字：">
                    </TextBlock>
                    <TextBlock Grid.Column="1" Grid.Row="1"  Text="{Binding Path=SelectedResource.Resource.KeyWords,Mode=OneWay}">
                    </TextBlock>
                    <TextBlock Grid.Column="0" HorizontalAlignment="Right" Grid.Row="2"  Foreground="Gray" Text="所属年龄段：">
                    </TextBlock>
                    <TextBlock Grid.Column="1" Grid.Row="2"  Text="{Binding Path=SelectedResource.Resource.SuitableAges,Mode=OneWay,Converter={StaticResource agesConverter}}">
                    </TextBlock>
                    <TextBlock Grid.Column="0" HorizontalAlignment="Right" Grid.Row="3"  Foreground="Gray" Text="故事简介：">
                    </TextBlock>
                    <TextBlock Grid.Column="1"  TextWrapping="Wrap" Grid.Row="3"  Text="{Binding Path=SelectedResource.Resource.Title,Mode=OneWay}">
                    </TextBlock>
                </Grid>
            </GroupBox>
            <ListBox Name="MainListBox" Grid.Row="0"  Background="Transparent" BorderBrush="LightBlue"
                 SelectionMode="Single" ItemsSource="{Binding Path=SelectedStatusDownloads,Mode=OneWay}"
                 SelectedIndex="{Binding Path=SelectedResourceIndex,Mode=TwoWay}"
                 > 
                <ListBox.ItemTemplate>                    
                    <DataTemplate>
                        <Border Name="ListBorder" BorderBrush="LightBlue"   BorderThickness="0,0,0,1" Padding="2,2,2,2">
                            <Border.ContextMenu >
                                <ContextMenu  Placement="MousePoint" >
                                    <MenuItem Header="继续下载" Name="ContinueDownload" Click="ContinueDownload_Click" ></MenuItem>
                                    <MenuItem Header="删除" Name="DeleteDownlaod" Click="DeleteDownlaod_Click"></MenuItem>
                                    <MenuItem Header="暂停" Name="PauseDownload" Click="PauseDownload_Click"></MenuItem>
                                </ContextMenu>
                            </Border.ContextMenu>
                            <Grid HorizontalAlignment="Stretch" Width="550">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="30"/>
                                    <ColumnDefinition Width="30"/>
                                    <ColumnDefinition Width="50"/>
                                    <ColumnDefinition Width="*"/> 
                                </Grid.ColumnDefinitions>
                                <CheckBox Name="SelectCheckBox" IsChecked="{Binding Path=Resource.Selected,Mode=TwoWay}" VerticalAlignment="Center" Grid.Column="0" Grid.Row="0" />
                                <Image Stretch="Uniform" Grid.Column="1" Grid.Row="0" Margin="2,0,2,0" Source="{Binding Path=Status,Mode=OneWay,Converter={StaticResource downloadStatusImageConverter}}"></Image>
                                <Image Stretch="Uniform" Grid.Column="2" Grid.Row="0" Margin="2,0,2,0" Source="{Binding Path=Resource.ThumbnailImgUrl,Converter={StaticResource imageSourceConverter}}"></Image>
                                <DockPanel  Grid.Column="3" Grid.Row="0" LastChildFill="True">
                                    <DockPanel DockPanel.Dock="Top" LastChildFill="True">
                                        <TextBlock DockPanel.Dock="Left" Padding="5,0,10,0" TextWrapping="Wrap" Text="{Binding Path=FileName}"></TextBlock>
                                        <StackPanel  Orientation="Horizontal"  HorizontalAlignment="Left"> 
                                            <ProgressBar Width="100" Orientation="Horizontal" Minimum="0" Maximum="1" Value="{Binding Path=Progress,Mode=OneWay}"></ProgressBar>
                                            <TextBlock >
                                                <TextBlock.Text>
                                                    <Binding Path="Progress" StringFormat=" {0:p2}"></Binding>
                                                </TextBlock.Text>
                                            </TextBlock>
                                        </StackPanel>
                                    </DockPanel>
                                    <Grid VerticalAlignment="Center">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="4*"/>
                                            <ColumnDefinition Width="3*"/>
                                            <ColumnDefinition Width="3*"/>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock  Grid.Column="0" Padding="5,0,0,0" HorizontalAlignment="Left"  Foreground="Gray">
                                            <TextBlock.Text>
                                                <Binding Path="SizeString" StringFormat="大小:{0}"></Binding>
                                            </TextBlock.Text>
                                        </TextBlock>
                                        <TextBlock Grid.Column="1" Padding="5,0,0,0" HorizontalAlignment="Left"  Foreground="Gray">
                                            <TextBlock.Text>
                                                <Binding Path="Speed" StringFormat="速度:{0:f2}KB"></Binding>
                                            </TextBlock.Text>
                                        </TextBlock>
                                        <TextBlock Grid.Column="2" Padding="5,0,0,0" HorizontalAlignment="Left" Foreground="Gray">
                                            <TextBlock.Text>
                                                <Binding Path="Resource.DownloadCount" StringFormat="下载次数:{0}"></Binding>
                                            </TextBlock.Text>
                                       </TextBlock>
                                        
                                        <!--<Image Grid.Column="3" HorizontalAlignment="Center" Stretch="Uniform" Source="/XbdSoft.WPFVersion;component/Images/yc.gif"></Image>-->
                                    </Grid>
                                </DockPanel> 
                            </Grid>
                        </Border>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>
    </Grid>
</UserControl>
